<?php
namespace app\admins\controller;
use think\Controller;
use Util\data\Sysdb;

    class Test extends Controller
    {
    public function index(){
    $this->db=new Sysdb;
    // $res = $this->db->table('admins')->field('id,username')->where(array('id'=>1))->item();
    // dump($res);
    //$res = $this->db->table('admins')->lists();
    //$results = [];
    //foreach ($res as $key => $value) {
    //	$results[] = $value;
    //}
    //dump($results);

    // $res2=$this->db->table('admins')->cates('id');
    //dump($res2);



    $menu_list = $this->db->table('admin_menus')->where(array('status'=>0))->cates('mid');
    // dump($menu_list);
    // exit;
    
    $menus = $this->gettreeitems($menu_list);
    dump($menus);
    
    

    
    }

    private function gettreeitems($items){
    $tree = array();
    foreach ($items as $item) {
        
        
        if(isset($items[$item['pid']])){
            $items[$item['pid']]['children'][] = &$items[$item['mid']];
        }
        else{
            //array_push($tree,$items[$item['mid']]);
            $tree[] = &$items[$item['mid']];
            //引用，把地址放在数组里，可以修改，push不可以修改
        }
    }
    
    return $tree;
    }

}

